ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS[:default] = '%Y-%m-%d %H:%M:%S'
ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS[:default] = '%Y-%m-%d %H:%M:%S'

class PatientDatasController < ApplicationController

  active_scaffold :patient_data do |config|
    config.label = " Pacjenci"
    
    config.columns = [
      :first_and_last_name,
      :first_name,
      :laste_name,
      :sex,
      :birth_date,
      :pesel,
      :street,
      :street_number,
      :city,
      :zip_code,
      :email,
      :telpehone_number,
      :created_at,
      :updated_at,
      :order_examinations,
      :user,
      :planed_examinations
    ]
    
    config.columns[:sex].form_ui  = :select
    config.columns[:user].form_ui  = :select

    columns[:first_and_last_name].label = 'Imię i Nazwisko:'
    columns[:first_name].label = "Imię:"
    columns[:laste_name].label = "Nazwisko:"
    columns[:sex].label = "Płeć:"
    columns[:pesel].label = "Pesel:"                      
    columns[:street].label = "Ulica:"
    columns[:street_number].label = "Numer:"
    columns[:city].label = "Miasto:"
    columns[:zip_code].label = "Kod zip:"
    columns[:email].label = "Adres email:"
    columns[:telpehone_number].label = "Numer telefonu:"
    columns[:created_at].label = "Utworzono:"
    columns[:updated_at].label = "Zmodyfikowano:"
    columns[:order_examinations].label = "Zlecenia na badanie:"
    columns[:user].label = "Pracownik:"
    columns[:user].clear_link
    columns[:birth_date].label = "Data urodzenia:"
    columns[:planed_examinations].label = "Zlecenia do wykonania:"


    config.create.columns.exclude  :order_examinations, :first_and_last_name, :user, :planed_examinations
    config.update.columns.exclude  :order_examinations , :first_and_last_name, :user, :planed_examinations
    config.list.columns.exclude  :created_at, :updated_at, :order_examinations, :first_name,  :laste_name,  :street,
      :street_number,
      :city,
      :zip_code,
      :birth_date, :planed_examinations
    
    config.show.columns.exclude  :first_and_last_name, :order_examinations
    
    config.nested.add_link("Pokaż zlecenia", [:order_examinations], :parameters => { :has_resoult => false, :is_checked => false })
    #config.nested.add_link("Pokaż wykonane", [:planed_examinations])

    list.per_page = 15
  end

  def before_create_save(record)
    record.user = current_user
  end

  def after_create_save(record)
    record.user = current_user
    flash[:info] = 'Pacjent został dodany'
  end

  def after_update_save(record)
    flash[:info] = 'Dane pacjenta zostały zmieniony'
  end
    
end
